<?php

namespace app\user\controller;

use app\user\logic\ShareLinkLogic;
use think\Controller;
use app\common\aliyun;
use think\facade\Config;
use think\facade\Request;

class Oss extends Controller
{

    protected $middleware = [
        'app\http\middleware\checkTTUserToken::class'=>['only'=>['auth']]
    ];

    //获取阿里云文件上传的授权
    public function auth()
    {
        $file_name=Request::param('file_name');
        $new_name= rand(1000,100000).time() .getSuffix($file_name);
        $user_id=Request::param('user_id');

        if(!ShareLinkLogic::checkMaxLink($user_id)){
            $this->result(0,400,'今天生成的链接数已经达到了最大值');
        }

        $this->result(aliyun\oss::getOssAuth(Config::get('oss.callback'),'video/'.$new_name),200,'授权签名成功');
    }

    //上传文件的回调
    public function callback(){
        $data= aliyun\oss::callback();
        $data['url']=Config::get('oss.host').'/'. $data['name'];            //文件的路径
        $this->result($data,'授权签名成功');
    }

}
